#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
from pyrogram import Client, filters
from pyrogram.errors import FloodWait
from time import sleep


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                     level=logging.INFO)

app = Client("my_account", api_id = 11111, api_hash = "aaaa")


@app.on_message(filters.command(["del all", "видалити все"],prefixes=".") & filters.me)
def handle_delete(_, msg):
    try:
        me_id = app.get_me().id
        app.delete_messages(msg.chat.id, [message.id for message in app.get_chat_history(msg.chat.id) if message.from_user.id == me_id])
    except FloodWait as e:
        print(f"FloodWait: {e.value+1} s")
        sleep(e.value + 1)
        handle_delete(_, msg)
    

app.run()
